package game.util;

import game.ChancePair;
import game.Constants;
import game.Person;
import game.Person.Gender;
import game.Person.Orientation;
import game.util.InterestUtil.Interest;
import game.util.TraitUtil.Trait;

import java.util.Collection;
import java.util.Vector;

public class PersonUtil {

	private String[] firstNamesMale = { "Matt", "Patrick", "Andrew", "John",
			"Eric", "Rob", "Dan", "Ian", "Derrek", "Adam", "Michael", "Nakael",
			"Jeff", "Garrett", "Taylor", "James" };
	private String[] firstNamesFemale = { "Erinn", "Britney", "Faye",
			"Margaret", "Sylvia", "Jane", "Eve", "Jessica", "Tasha", "Andrea",
			"Jennifer", "Kaylee" };
	private String[] lastNames = { "Church", "Smith", "Nickerson", "Campbell",
			"Graves", "Yake", "Dowling", "Bell", "Neumann", "Sifeldeen",
			"Kanhai", "Narayan", "Andrews", "Bohumechuk", "Legg", "Turcotte" };

	public Person GenerateRandomPerson() {
		// Gender
		final Gender gender = (Gender) Util.GetRandomEnumValue(Gender.values());

		// Traits
		final TraitUtil traitGenerator = new TraitUtil();
		final Collection<Trait> traits = traitGenerator.getRandomTraits();

		// Interests
		final InterestUtil interestGenerator = new InterestUtil();
		final Collection<Interest> interests = interestGenerator
				.getRandomInterests();

		// FirstName
		final String firstName = GetFirstName(gender);

		// LastName
		final String lastName = GetLastName();

		// Looks
		final int looks = GetBaseLooks();

		// Orientation
		final Orientation orientation = GetOrientation();

		Person person = new Person(firstName, lastName, traits, interests,
				gender, looks, orientation);
		// Util.log("Generated Random Person: " + person + "\n");
		return person;
	}

	private Orientation GetOrientation() {
		final Collection<ChancePair<Orientation>> orientations = new Vector<ChancePair<Orientation>>();
		final ChancePair<Orientation> straight = new ChancePair<Person.Orientation>(
				Orientation.STRAIGHT, Constants.CHANCE_STRAIGHT);
		final ChancePair<Orientation> gay = new ChancePair<Person.Orientation>(
				Orientation.GAY, Constants.CHANCE_GAY);
		final ChancePair<Orientation> bisexual = new ChancePair<Person.Orientation>(
				Orientation.BISEXUAL, Constants.CHANCE_BISEXUAL);
		orientations.add(straight);
		orientations.add(bisexual);
		orientations.add(gay);
		return Util.GetRandomFromChancePair(orientations);
	}

	private int GetBaseLooks() {
		return Util.GetRandomIntBetween(Constants.BASE_LOOKS_MIN,
				Constants.BASE_LOOKS_MAX);
	}

	private String GetFirstName(Gender gender) {
		if (gender == Gender.MALE)
			return Util.GetRandomString(firstNamesMale);
		else
			return Util.GetRandomString(firstNamesFemale);
	}

	private String GetLastName() {
		return Util.GetRandomString(lastNames);
	}

	public Collection<Person> generateRandomPeople(int numNewPeoplePerHour) {
		Collection<Person> people = new Vector<Person>();
		for (int i = 0; i < numNewPeoplePerHour; ++i) {
			people.add(GenerateRandomPerson());
		}
		return people;
	}
}
